package cn.merryyou.jpa.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@Data
@Table(name = "user")
@NoArgsConstructor
public class User implements Serializable {

    private static final long serialVersionUID = -4639053674311818899L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    @Column(name = "user_name")
    private String userName;
    private String name;
    @Column(name = "create_time")
    private Date createTime;
    @OneToMany(mappedBy = "redPackage")
    private Set<UserPackage> userPackages = new HashSet<>();

    public User(String userName, String name, Date createTime) {
        this.userName = userName;
        this.name = name;
        this.createTime = createTime;
    }

    public User(String userName) {
        this.userName = userName;
        this.createTime = new Date();
    }
}
